package gateway.server.route;

import gateway.api.engine.Connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * @author Jin Zheng
 * @since 1.0 2020-09-11
 */
public class RouteManagement
{
	private static Logger logger = LoggerFactory.getLogger(RouteManagement.class);

	private List<Connector> connectors = new ArrayList<>();
	private Map<String, SortedSet<Route>> routes = new HashMap<>();
	private List<Object> objectList = new ArrayList<>();

	public RouteManagement()
	{
	}

	public void addConnector(Connector connector)
	{
		connectors.add(connector);
	}

	public List<Connector> connectors()
	{
		return connectors;
	}

	public SortedSet<Route> getRoutes(String connectorId)
	{
		return routes.get(connectorId);
	}

	public void add(String connectorId, Route route)
	{
		SortedSet<Route> set = routes.computeIfAbsent(connectorId, k -> new TreeSet<>());
		set.add(route);
	}

	public void addObject(Object object)
	{
		objectList.add(object);
	}

	public List<Object> objects()
	{
		return objectList;
	}

}
